<?php
// +----------------------------------------------------------------------
// | 管理员控制器
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\admin\service\SysUserService;
use think\facade\View;
use think\captcha\facade\Captcha;

class PublicController extends AdminController
{
    public function login(){
        return View::fetch('public/login');
    }

    public function loginPost(){
        $data = $this->request->post();
        //验证规则
        $validate = [
            'username' => 'require',
            'password'  => 'require',
            'captcha' => 'require',
        ];
        //提示信息
        $message = [
            'account.require' => '账号不能为空!',
            'password.require' => '密码不能为空!',
            'captcha.require' => '验证码不能为空!',
        ];

        $this->validate($data, $validate, $message);

        if(!Captcha::check($data['captcha']))
        {
            return failure(3004, "输入的验证码不正确！");
        }

        SysUserService::login($data);
        return success();
    }

}
